<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    
    <title>后台管理</title>
    
	<link rel="stylesheet" type="text/css" href="<%=path%>/JS/extjs/resources/css/ext-all.css" />
	<link rel="stylesheet" type="text/css" href="<%=path%>/JS/extjs/ux/statusbar/css/statusbar.css" />
	
	<script type="text/javascript" src="<%=path%>/JS/extjs/adapter/ext-base.js"></script>
	<script type="text/javascript" src="<%=path%>/JS/extjs/ext-all.js"></script>
	<script type="text/javascript" src="<%=path%>/JS/extjs/ext-lang-zh_CN.js"></script>
	<script type="text/javascript" src="<%=path%>/JS/jquery-1.7.2.js"></script>
	
	
	<link rel="stylesheet" type="text/css" href="<%=path%>/JS/extjs/ux/statusbar/css/statusbar.css" />
	<script type="text/javascript" src="<%=path%>/JS/extjs/ux/statusbar/StatusBar.js"></script>
	<script type="text/javascript" src="<%=path%>/JS/extjs/ux/statusbar/ValidationStatus.js"></script>

	
	<script type="text/javascript">
		
	
	</script>
  </head>
  
  <body>
  	<s:hidden id="menu" value="#request.parentmenulist"></s:hidden>
    <input type="hidden" id="parentmenu" value="#request.parentmenulist"/>
    
    <script type="text/javascript">
   // var arrMenu = new Array();
	$(function(){
		//加载菜单项
		/*	$.ajax({  
				url:'adminMenu',  
				type:'POST',  
				data:"{}",  
				dataType:'json',
				timeout: 100000,
				async:true,               
				error: function(a){                     
					alert('出错了');                 
				},   
				success:function (data) { 
					arrMenu = data.menuList; 
				    //$("#allUser").append("输出了：id:" + data.hello);  
				    alert(arrMenu);
				    //addToolMenu();
				}  
				});*/
	});

    function InitMain(){
        var toolbar = new Ext.Toolbar({
            id:'toolbar',
            border:'false',
            x:0,
            y:0,
            items:[{
                	id:'index',
                	text:'首页',
                	xtype:'tbbutton',
                	cls:'x-btn-text.icon',
                	handler:function(){
            			var tabpaneltemp = Ext.getCmp("home");
            			var tabpanel = Ext.getCmp("tabpanel");
            			//alert(tabpaneltemp);
            			if(tabpaneltemp == null){
                			//alert(1111111);
							tabpaneltemp = new Ext.Panel({
								id : "home",
								title : "首页",
								xtype : "panel",
								layout : "fit",
								border : "false",
								frame : "false",
								closable : "true",
								html : "<b><s:property value="#session.adminUser.username"/></b>,欢迎你进入后台管理系统"
							});
							tabpanel.add(tabpaneltemp);
							
						}
        				tabpanel.setActiveTab(tabpaneltemp);//显示打开的页签
            		}
            	}
                  ]
        });
        var tabpanel = new Ext.TabPanel({
        	id:"tabpanel",
        	activeTab:0,
        	autoWidth:true,
        	border:false,
        	frame:false,
        	items : [
        	         {
            	         id:"home",
            	        xtype : "panel",
            	        title : "首页",
            	        layout : "fit",
            	        closable : "true",
            	        border : "false",
            	        frame : "false",
            	        html : "<b><s:property value="#session.adminUser.username"/></b>，欢迎你进入后台管理系统 " 
            	     }
        	]
        });
        var northPanel = new Ext.Panel({
            id:'northPanel',
            region:'north',
            //height:35,
            tbar:[toolbar]//此处加上'[]'与不加在页面显示的按钮有区别
        });
      //状态栏

        var southPanel = new Ext.Panel({
            region:"south",
            height:30,
            frame:false,
            border: false,
            bbar: [{
                    xtype: "button",
                    text: "<b>退出</b>",
                    iconCls : 'remove',
                    handler: function () {
                    	window.location = "<%=path%>/login.jsp";
                    }
                }]
        });
        
        var westPanel = new Ext.Panel({
            id:'westPanel',
        	title:'导航菜单',
        	region:'west',
        	width:'200',
        	split:true,
        	collapsible: true,
        	margins:'0 0 0 0',
            layout:'accordion',
            layoutConfig:{animate:false}/*,
            items : [
                     treePanel1,
                     treePanel2
                     ]*/
        });
		var centerPanel = new Ext.Panel({
			id : 'centerPanel',
			//title : '中心部分',
			region: 'center',
			split:true,
            layout:'fit', 
            items:[tabpanel]
			});

		var viewport = new Ext.Viewport({
			id : 'viewprot',
			layout : 'border',
			items : [
						northPanel,
						southPanel,
						westPanel,
						centerPanel
			]
		});
		//静态加载菜单
	    staticAddMenu();
	    //动态加载菜单
	    //addToolMenu();
	}
    	
    Ext.onReady(InitMain); 


    function addToolMenu(){
    	var arrMenu = new Array();
    	$.ajax({  
			url:'adminFindMenu',  
			type:'POST',  
			data:"{}",  
			dataType:'json',
			timeout: 100000,
			async:true,               
			error: function(a){                     
				alert('出错了');                 
			},   
			success:function (data) { 
				arrMenu = data.menuList; 
			    //$("#allUser").append("输出了：id:" + data.hello);  
			 //  alert(arrMenu);
			    //addToolMenu();
		        var toolbars = Ext.getCmp("toolbar");
		        alert(toolbars);
		        var westPanel = Ext.getCmp("westPanel");
		        for(var i=0;i<arrMenu.length;i++){
		            var parentId = arrMenu[i].parentid;
		            if(parentId == 0){
			            var btnId = arrMenu[i].id;
			            var btnText = arrMenu[i].text;
			            var childrenarr = arrMenu[i].children;
					    //添加菜单按钮
			            var toolbtn = new Ext.Button({
				        	id : btnId,
						    text : btnText,
						  	xtype : "tbbutton",
						    cls : 'x-btn-text-icon',
						    listeners : {
						    	"click" : function(o,e){
						    	//alert(o.id);
						    	//展开对应的Panel(o为当前按扭的对象，可得到其id)
				            	var mainpanel = Ext.getCmp("panel" + o.id);
								mainpanel.expand(true); 
			            		}
						    }
			            });
			            toolbars.addItem(toolbtn);
			            //添加左侧菜单项
			           	var westSubPanel = new Ext.Panel({
			           		xtype : "treepanel",
			    			id : "panel" + btnId,
			    			title : btnText,
			    			border : false,
			    			layout:'fit',
			    			border: false,
			    			frame:true,
			    			items:
			    	            [{
			    	                 xtype:'treepanel',
			    	                 singleExpand:true,
			    	                 animate:true,
			    	                 autoScroll:true,
			    	                 containerScroll: true,
			    	                 border: false,
			    	                 rootVisible:false,
			    	                 lines:true,
			    	                 width:200,
			    	                 height:370,
			    	                 enableDD:false,
			    	                 dropConfig: {appendOnly:true},                          
			    	                 loader: new Ext.tree.TreeLoader({
			    						 preloadChildren: true,
			    					     clearOnLoad: false
			    						 //dataUrl:"json.aspx?Param=1"
			    						 }),                          
			    	                 root:new Ext.tree.AsyncTreeNode({
			    	                    id:"tree"+btnId,
			    	                    text: btnText,
			    	                    draggable:false,
			    	                    expanded:true,
			    						leaf:false,
			    						children:childrenarr
			    	                  })
			    	                  ,listeners:{"click": function(node,e){
			    								if (node.leaf)
			    								{//node.attributes.xxx得到树结点属性中存在的，但不是其本身属性的值
			    									//alert(node.text+"你点的是："+node.attributes.jspurl + "::w::" + node.id );
			    									var tabpaneltemp = Ext.getCmp("tab"+node.id);
			    									var tagerturl = node.attributes.jspurl;
			    									if (tabpaneltemp==null)
			    									{
			    										tabpaneltemp = new Ext.Panel
			    										({
			    								             id:"tab"+node.id,
			    								             xtype:"panel",
			    								             layout:'fit',
			    								             title:node.text,
			    								             closable:true,
			    								             border:false,
			    								             frame:false,//iconCls:'panel_icon',
			    											html:"<iframe scrolling='no' width='100%' height='100%'  frameborder='0' src='"+tagerturl+"'></iframe>"
			    										});
			    										Ext.getCmp("tabpanel").add(tabpaneltemp);
			    									}
			    									Ext.getCmp("tabpanel").setActiveTab("tab"+node.id);
			    								}							
			    							}}
			    	                 }]
			           	});
			           	westPanel.add(westSubPanel);
			           	toolbars.doLayout();
			           	westPanel.doLayout();
		            }
		            
		        }
			}  
			});
    }

    function staticAddMenu(){
        var menuStr = "[{'id':1,'text':'注册管理','jspurl':null,"
	 		+ "'children':[{'jspurl':'admin/admin_audiencemanager.jsp?type=0','id':4,'text':'登记用户管理','parentid':1,'isavailable':1,'leaf':'true'},"
	 		+ "{'jspurl':'admin/admin_companymanager.jsp?type=0','id':14,'text':'参展企业管理','parentid':1,'isavailable':1,'leaf':'true'}],"
	 		+ "'parentid':0,'leaf':'false','isavailable':1},"

	 		+ "{'id':2,'text':'调查问卷管理','jspurl':null,'children':["
	 		+ "{'jspurl':'admin/admin_qtitlemanager.jsp?type=0','id':5,'text':'调查问卷标题管理','parentid':2,'isavailable':1,'leaf':'true'},"
	 		+ "{'jspurl':'admin/admin_qcontentmanager.jsp?type=0','id':6,'text':'调查问卷内容管理','parentid':2,'isavailable':1,'leaf':'true'}"
	 		+ "],'parentid':0,'leaf':'false','isavailable':1},"

	 		+ "{'id':3,'text':'管理员管理','jspurl':null,"
	 		+ "'children':[{'jspurl':'admin/\admin_setAdminUserInfo.jsp','id':9,'text':'管理员设置','parentid':3,'isavailable':1,'leaf':'true'}],"
	 		+ "'parentid':0,'leaf':'false','isavailable':1},"
	 		+ "{'id':7,'text':'邮箱设置','jspurl':null,"
	 		+ "'children':[{'jspurl':'admin/admin_setemailserver.jsp','id':8,'text':'邮箱设置','parentid':7,'isavailable':1,'leaf':'true'}],"
	 		+ "'parentid':0,'leaf':'false','isavailable':1},"

	 		+ "{'id':11,'text':'展会信息管理','jspurl':null,"
	 		+ "'children':[{'jspurl':'admin/admin_showInfoManger.jsp','id':12,'text':'展会信息设置','parentid':11,'isavailable':1,'leaf':'true'}],"
	 		+ "'parentid':0,'leaf':'false','isavailable':1}]";
 		
        var arrMenu = Ext.util.JSON.decode(menuStr);
       // alert(arrMenu);
	    var toolbars = Ext.getCmp("toolbar");
        //alert(toolbars);
        var westPanel = Ext.getCmp("westPanel");
        for(var i=0;i<arrMenu.length;i++){
            var parentId = arrMenu[i].parentid;
            if(parentId == 0){
	            var btnId = arrMenu[i].id;
	            var btnText = arrMenu[i].text;
	            var childrenarr = arrMenu[i].children;
			    //添加菜单按钮
	            var toolbtn = new Ext.Button({
		        	id : btnId,
				    text : btnText,
				  	xtype : "tbbutton",
				    cls : 'x-btn-text-icon',
				    listeners : {
				    	"click" : function(o,e){
				    	//alert(o.id);
				    	//展开对应的Panel(o为当前按扭的对象，可得到其id)
		            	var mainpanel = Ext.getCmp("panel" + o.id);
						mainpanel.expand(true); 
	            		}
				    }
	            });
	            toolbars.addItem(toolbtn);
	            //添加左侧菜单项
	           	var westSubPanel = new Ext.Panel({
	           		xtype : "treepanel",
	    			id : "panel" + btnId,
	    			title : btnText,
	    			border : false,
	    			layout:'fit',
	    			border: false,
	    			frame:true,
	    			items:
	    	            [{
	    	                 xtype:'treepanel',
	    	                 singleExpand:true,
	    	                 animate:true,
	    	                 autoScroll:true,
	    	                 containerScroll: true,
	    	                 border: false,
	    	                 rootVisible:false,
	    	                 lines:true,
	    	                 width:200,
	    	                 height:370,
	    	                 enableDD:false,
	    	                 dropConfig: {appendOnly:true},                          
	    	                 loader: new Ext.tree.TreeLoader({
	    						 preloadChildren: true,
	    					     clearOnLoad: false
	    						 //dataUrl:"json.aspx?Param=1"
	    						 }),                          
	    	                 root:new Ext.tree.AsyncTreeNode({
	    	                    id:"tree"+btnId,
	    	                    text: btnText,
	    	                    draggable:false,
	    	                    expanded:true,
	    						leaf:false,
	    						children:childrenarr
	    	                  })
	    	                  ,listeners:{"click": function(node,e){
	    								if (node.leaf)
	    								{//node.attributes.xxx得到树结点属性中存在的，但不是其本身属性的值
	    									//alert(node.text+"你点的是："+node.attributes.jspurl + "::w::" + node.id );
	    									var tabpaneltemp = Ext.getCmp("tab"+node.id);
	    									var tagerturl = node.attributes.jspurl;
	    									if (tabpaneltemp==null)
	    									{
	    										tabpaneltemp = new Ext.Panel
	    										({
	    								             id:"tab"+node.id,
	    								             xtype:"panel",
	    								             layout:'fit',
	    								             title:node.text,
	    								             closable:true,
	    								             border:false,
	    								             frame:false,//iconCls:'panel_icon',
	    											html:"<iframe scrolling='no' width='100%' height='100%'  frameborder='0' src='"+tagerturl+"'></iframe>"
	    										});
	    										Ext.getCmp("tabpanel").add(tabpaneltemp);
	    									}
	    									Ext.getCmp("tabpanel").setActiveTab("tab"+node.id);
	    								}							
	    							}}
	    	                 }]
	           	});
	           	westPanel.add(westSubPanel);
	           	toolbars.doLayout();
	           	westPanel.doLayout();
            }
            
        }
    }


  </script>
  </body>
</html>

